<#assign baseURL = springMacroRequestContext.getContextPath() />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拓深科技</title>
<#include "./css.ftl">
    <style type="text/css">
        .mapBall{
            width:20px;
            height:20px;
            background: red;
            border-radius: 50%;
            position: absolute;
        }
        .table>tbody>tr>td{
            text-align:center;
            line-height: 15px;
            font-size: 15px;
        }
        .table>thead:first-child>tr:first-child>th{
            text-align:center;
        }
    </style>
</head>
<body>
<div id="wrapper">

<#include "./left_nav.ftl">

    <div id="page-wrapper" class="gray-bg dashbard-1 animated fadeInRight">
    <#include "./top_nav.ftl">
        <div class="wrapper wrapper-content">
            <div class="row">

                <#if (role_type_id > 3)>
                    <div class="widget red-bg p-lg text-center">
                        <div class="m-b-lg">
                            <i class="fa fa-bell fa-4x" style="margin-bottom: 20px"></i>
                            <h1 class="font-bold no-margins">
                                权限不足
                            </h1>
                        </div>
                    </div>
                <#else >

                    <div class="col-md-12" >
                        <div class="nav-tabs-custom" >
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_2" data-toggle="tab">监测点列表</a> </li>
                                <li><a href="#tab_1" data-toggle="tab">监测点录入</a> </li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab_2">
                                        <div class="panel panel-default " style="margin-bottom: 0px">
                                            <div class="panel-body">
                                                <table id="del_data_table" class="table table-bordered table-striped" width="100%" cellspacing="0">
                                                    <thead>
                                                    <tr>
                                                        <th>报警回路号</th>
                                                        <th>监测点名称</th>
                                                        <th>所属用户信息传输装置</th>
                                                        <th>用户信息传输装置IP</th>
                                                        <th>传感器类型</th>
                                                        <th>区域</th>
                                                        <th>建筑物</th>
                                                        <th>楼层</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="del_data_table_tbody">

                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                </div>
                                <div class="tab-pane " id="tab_1">
                                    <div class="panel panel-default" style="padding: 5px 0 0 5px;">
                                        <div class="panel-header">
                                            <h4 class="panel-title"><b>1 选择传感器类别</b></h4>
                                        </div>
                                        <div class="panel-body" id="sensor_div">
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label>一级</label>
                                                    <select id="sensor_select_level1"  class="form-control select2 sensor_level_1" style="width: 100%;">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label>二级</label>
                                                    <select id="sensor_select_level2" class="form-control select2 sensor_level_2" style="width: 100%;">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-4 ">
                                                <div class="form-group">
                                                    <label>三级</label>
                                                    <select id="sensor_select_level3" class="form-control select2 sensor_level_3" style="width: 100%;">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel panel-default" style="padding: 5px 0 0 5px;">
                                        <div class="panel-header">
                                            <h4 class="panel-title"><b>2 选择地图</b></h4>
                                        </div>
                                        <div id="loction_input_div" class="panel-body">
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label>区域</label>
                                                    <select id="area_select"  class="form-control select2 input_area" style="width: 100%;">

                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label>建筑物</label>
                                                    <select id="build_select" class="form-control select2 input_build" style="width: 100%;">

                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-4 ">
                                                <div class="form-group">
                                                    <label>楼层</label>
                                                    <select id="floor_select" class="form-control select2 input_floor" style="width: 100%;">

                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel panel-default" style="padding: 5px 0 0 5px;">
                                        <div class="panel-header">
                                            <h4 class="panel-title"><b>3 录入传感器信息</b></h4>
                                        </div>
                                        <div class="panel-body">
                                            <div class="col-md-3 ">
                                                <div class="form-group">
                                                    <label>名称</label>
                                                    <input id="sensor_name_input" type="text" class="form-control" placeholder="请输入名称">
                                                </div>
                                            </div>
                                            <div class="col-md-3 " id="eq_select_div">
                                                <div class="form-group">
                                                    <label>所属用户信息传输装置</label>
                                                    <select id="router_select" class="form-control select2 eq_select">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-2 ">
                                                <div class="form-group">
                                                    <label>报警回路号</label>
                                                    <input id="alert_code_input" type="text" class="form-control" placeholder="请输入报警回路号">
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="col-sm-4 ">
                                                    <div class="form-group">
                                                        <label>坐标X</label>
                                                        <input id="map_pos_x" type="text" class="form-control" disabled>
                                                    </div>
                                                </div>
                                                <div class="col-sm-4 ">
                                                    <div class="form-group">
                                                        <label>坐标Y</label>
                                                        <input id="map_pos_y" type="text" class="form-control" disabled>
                                                    </div>
                                                </div>
                                                <div class="col-sm-4">
                                                    <button id="saveMonitorBtn" type="button" class="btn btn-success btn-block pull-right"  style="margin-top: 22px"><i class="fa fa-upload"></i> 提交</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel panel-default" style="padding: 5px 0 0 5px;">
                                        <div class="panel-header">
                                            <h4 class="panel-title"><b>4 标注坐标点</b></h4>
                                        </div>
                                        <div class="panel-body">
                                            <div  id="monitor_map_div" class="ip_slide">

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </#if>

            </div>
        </div>
    <#include "./bottom_nav.ftl">
    </div>

</div>


<#include "./js.ftl">

<#if (role_type_id > 3)>

<#else >
<script>
    var loctionData;
    var monitorTable;
    var pageIndex = 1;
    var server = "http://"+getURL()+"${baseURL}";
    var sensorData = [];
    var eqData = [];
    var mapData = [];
    $(function () {
        socketInit(server.substring(5));
        loadLoctionData();
        getSensorType();
        getEQ();
        initMonitorTable();
    });
    function getEQ() {
        $.ajax({
            url:"${baseURL}/xkDevice/getAll",
            success:function (data) {
                eqData = data;
                $('#eq_select_div').cxSelect({
                    selects: ['eq_select'],
                    jsonName: 'name',
                    jsonValue: 'id',
                    data:eqData.data
                });
            }
        });
    }
    function loadLoctionData() {
        $.ajax({
            url: "${baseURL}/xkGeoLocation/getTree",
            async:false,
            type:"GET",
            success:function (data_in) {
                var jsonObj = data_in;
                mapData = [];
                var data = [];
                for(var i  in jsonObj.data){
                    var level1 = jsonObj.data;
                    var level1Obj = {
                        text:level1[i].name,
                        id:level1[i].id,
                    };
                    if(level1[i].children != null)
                    {
                        var level2 = level1[i].children;
                        var level2Arr = [];
                        for(var j in level2){
                            var level2Obj = {
                                text: level2[j].name,
                                id: level2[j].id,
                            };
                            if(level2[j].children != null)
                            {
                                var level3 = level2[j].children;
                                var level3Arr = [];
                                for(var k in level3){
                                    var level3Obj = {
                                        text: level3[k].name,
                                        id: level3[k].id,
                                    };
                                    level3Arr.push(level3Obj);
                                    var floorObj = {
                                        id: level3[k].id,
                                        picture: level3[k].picture
                                    };
                                    mapData.push(floorObj);
                                }
                                level2Obj .children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    data.push(level1Obj);
                }
                loctionData = data;
            }
        });
        $('#loction_input_div').cxSelect({
            selects: ['input_area', 'input_build', 'input_floor'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:loctionData
        });
        $('#loction_delete_div').cxSelect({
            selects: ['delete_area', 'delete_build', 'delete_floor'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:loctionData
        });
    }
    function getSensorType() {
        $.ajax({
            url:"${baseURL}/xkSensor/getTree",
            async:false,
            type:"GET",
            success:function (data_in) {
                var jsonObj = data_in;
                sensorData = [];
                for(var i in jsonObj.data){
                    var level1Data = jsonObj.data;
                    var level1Obj = {
                        id: level1Data[i].id,
                        text: level1Data[i].name,
                    };
                    if(level1Data[i].children != undefined){
                        var level2Data = level1Data[i].children;
                        var level2Arr = [];
                        for(var j in level2Data){
                            var level2Obj = {
                                text: level2Data[j].name,
                                id: level2Data[j].id,
                            };
                            if(level2Data[j].children != undefined)
                            {
                                var level3Data = level2Data[j].children;
                                var level3Arr = [];
                                for(var k in level3Data){
                                    var level3Obj = {
                                        text: level3Data[k].name,
                                        id: level3Data[k].id,
                                    };
                                    level3Arr.push(level3Obj);
                                }
                                level2Obj.children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    sensorData.push(level1Obj);
                }
            }
        });
        $('#sensor_div').cxSelect({
            selects: ['sensor_level_1', 'sensor_level_2','sensor_level_3'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:sensorData
        });
    }

    function initMonitorTable() {
        monitorTable = $('#del_data_table').DataTable({
            columns:[
                {data: "monitor_description"},
                {data: "monitor_name"},
                {data: "device_name"},
                {data: "device_ip"},
                {data: "sensor_name"},
                {data: "geo_1"},
                {data: "geo_2"},
                {data: "geo_3"},
                {data: "id","width":"15%"}
            ],
            columnDefs:[{
                targets:8,
                render: function (data, type, row, meta) {
                    return   '<div  class="col-sm-12" style="padding: 0 0 0 0;"><div class="col-sm-6" style="padding: 0 2px 0 0;"><button <#if (role_type_id > 2)>disabled</#if>  onclick="editRecord('+data+')" type="button" class="btn btn-block btn-success" style="padding: 0 0 0 0;"><i class="fa fa-pencil-square-o"></i>&nbsp;&nbsp;编&nbsp;辑</button></div> <div class="col-sm-6" style="padding: 0 2px 0 0;"><button <#if (role_type_id > 2)>disabled</#if> onclick="delMonitor('+data+')" type="button" class="btn btn-block btn-warning" style="padding: 0 0 0 0;"><i class="fa fa-trash"></i>&nbsp;&nbsp;删&nbsp;除</button></div></div>'
                }
            },
                {   'orderable': false,
                    'targets': 5
                }],
            destroy: true,
            ajax: "${baseURL}/xkMonitor/getAll",
            language:{
                "sProcessing":   "处理中...",
                "sLengthMenu":   "显示 _MENU_ 项结果",
                "sZeroRecords":  "没有匹配结果",
                "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix":  "",
                "sSearch":       "搜索:",
                "sUrl":          "",
                "sEmptyTable":     "表中数据为空。",
                "sLoadingRecords": "载入中...",
                "sInfoThousands":  ",",
                "oPaginate": {
                    "sFirst":    "首页",
                    "sPrevious": "上页",
                    "sNext":     "下页",
                    "sLast":     "末页"
                },
                "oAria": {
                    "sSortAscending":  ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    };
    function delMonitor(id) {
        var index = layer.load(0, {shade: false});
        $.ajax({
            url:'${baseURL}/xkMonitor/delete?id=' + id,
            success:function (data) {
                layer.alert('数据删除成功！',{
                    closeBtn: 0
                });
                monitorTable.ajax.reload();
                layer.close(index);
            }

        });
    }
    function mapOnClick(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#map_pos_x').val(x.toFixed(10));
        $('#map_pos_y').val(y.toFixed(10));
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#monitor_map_div .mapBall").remove();
        }
        posSetBall(x,y)
    }
    function posSetBall(x,y) {
        var pos_x = (parseFloat(x) * 100);
        pos_x = pos_x>0?pos_x+'%':0;
        var pos_y = (parseFloat(y) * 100);
        pos_y = pos_y>0?pos_y+'%':0;
        $('<span class="mapBall ip_tooltip" style="top:calc('+pos_y+' - 10px);left: calc('+pos_x+' - 10px")>').css({
            width: 20,
            height: 20,
        }).appendTo($('#monitor_map_div '));
    }

    $('#floor_select').change(function () {
        var ID = $('#floor_select').val();
        for(var i in mapData){
            if(mapData[i].id == ID){
                var picture = mapData[i].picture;
                $('#monitor_map_div').empty();
                if(picture != ""){
                    $('#monitor_map_div').append(
                            '<img id="monitor_map" src="${baseURL}/xkGeoLocationMap/mapDownload?id='+ID+'"  class="ip_tooltipImg " style="margin:0 auto;padding:0; width:100%" onclick="mapOnClick(event)"/>'
                    );
                }
                else{
                    layer.alert('服务器未存储地图数据！请先录入！',{
                        closeBtn: 0
                    });
                }
                break;
            }
        }
    });
    $('#saveMonitorBtn').click(function () {
        var sensor_level_3 = $("#sensor_select_level3").val();
        var geo_level_1 = $("#area_select").val();
        var geo_level_2 = $("#build_select").val();
        var geo_level_3 = $("#floor_select").val();
        var device_id =$("#router_select").val();
        var name = $('#sensor_name_input').val();
        var alarm_no = $('#alert_code_input').val();
        var pos_x = $('#map_pos_x').val();
        var pos_y = $('#map_pos_y').val();
        var formDatas = new FormData();
        formDatas.append("sensor_id",sensor_level_3);
        formDatas.append("geo_level_1_id",geo_level_1);
        formDatas.append("geo_level_2_id",geo_level_2);
        formDatas.append("geo_level_3_id",geo_level_3);
        formDatas.append("device_id",device_id);
        formDatas.append("name",name);
        formDatas.append("code",alarm_no);
        formDatas.append("pos_x",pos_x);
        formDatas.append("pos_y",pos_y);

        if(name&&alarm_no&&device_id&&sensor_level_3&&geo_level_3){
            if(isSpecial(name)){
                layer.alert('名称不能含有特殊字符',{
                    closeBtn: 0
                });
            }else{
                $.ajax({
                    type:"post",
                    contentType : false,
                    processData:false,
                    url:'${baseURL}/xkMonitor/add',
                    data:formDatas,
                    success:function (data) {
                        if(data.code == 0){
                            layer.alert('数据录入成功！',{
                                closeBtn: 0
                            });
                            monitorTable.ajax.reload();
                        }
                        else{
                            layer.alert('操作失败：' + data,{
                                closeBtn: 0
                            });
                        }
                    }
                });
            }

        }else {
            layer.alert('请输入完整的筛选信息！',{
                closeBtn: 0
            });
        }
    });
    function editRecord(id) {
        var sensorLevel1;
        var sensorLevel2;
        var sensorLevel3;
        var name;
        var deviceId;
        var geoLevel1;
        var geoLevel2;
        var geoLevel3;
        var posX;
        var posY;
        var alarmNo;
        layer.open({
            type: 1,
            title:'监测点编辑',
            skin:'layui-layer-lan',
            area:['1000px', '100%'],
            maxmin:true,
            maxHeight:'1000px',
            scrollbar: false,
            content:'<div class="tab-pane" id="tab_0" style="width:100%;height:100%;margin-left: 0px">'
            +'  <div class="row" style="width:100%;height:100%;margin-left: 0px">'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="panel-heading">'
            +'                          <h4>2.1 传感器类别</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div id="monitor_sensor_change_div">'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>一级</label>'
            +'                                  <select id="monitor_change_sensor1_select" class="form-control select2 monitor_change_sensor1_select_class" value></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>二级</label>'
            +'                                  <select id="monitor_change_sensor2_select" class="form-control select2 monitor_change_sensor2_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>三级</label>'
            +'                                  <select id="monitor_change_sensor3_select" class="form-control select2 monitor_change_sensor3_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3" id="monitor_change_router_div">'
            +'                          <div class="form-group">'
            +'                              <label>用户信息传输装置</label>'
            +'                              <select id="monitor_change_router_select" class="form-control select2 monitor_change_router_select_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="panel-heading">'
            +'                          <h4 >2.2 监测点地理位置</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="" id="monitor_change_location_div">'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>区域</label>'
            +'                              <select id="monitor_change_area_select2" class="form-control select2 monitor_change_area_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>建筑物</label>'
            +'                              <select id="monitor_change_build_select2" class="form-control select2 monitor_change_build_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>楼层</label>'
            +'                              <select id="monitor_change_floor_select2" class="form-control select2 monitor_change_floor_select2_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="panel-heading">'
            +'                          <h4 >2.3 设定新监测点名称与坐标点</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="col-sm-3">'
            +'                          <div class="form-group">'
            +'                              <label>监测点名称</label>'
            +'                              <input id="monitor_change_name_input" type="text" class="form-control" placeholder="请输入监测点名称">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3 ">'
            +'                          <div class="form-group">'
            +'                              <label>报警回路号</label>'
            +'                              <input id="monitor_change_alert_number_input" type="text" class="form-control">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2">'
            +'                          <div class="form-group">'
            +'                              <label>监测点X坐标</label>'
            +'                              <input id="monitor_change_pos_x_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2 ">'
            +'                          <div class="form-group">'
            +'                              <label>监测点Y坐标</label>'
            +'                              <input id="monitor_change_pos_y_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div class="panel-heading">'
            +'                          <h4>地图点选</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row" style="width:100%;margin-left: 0px">'
            +'                      <div id="monitor_change_map_div"class="ip_slide" style="width:100%">'
            +'                      </div>'
            +'                  </div>'
            +'  </div>'
            +'</div>'
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                var sensor_id = $('#monitor_change_sensor3_select').val();
                var geo_level_1_id = $('#monitor_change_area_select2').val();
                var geo_level_2_id = $('#monitor_change_build_select2').val();
                var geo_level_3_id = $('#monitor_change_floor_select2').val();
                var device_id = $('#monitor_change_router_select').val();
                var name = $('#monitor_change_name_input').val();
                var code = $('#monitor_change_alert_number_input').val();
                var pos_x = $('#monitor_change_pos_x_input').val();
                var pos_y = $('#monitor_change_pos_y_input').val();
                var formDatas = new FormData();
                formDatas.append("id",id);
                formDatas.append("sensor_id",sensor_id);
                formDatas.append("geo_level_1_id",geo_level_1_id);
                formDatas.append("geo_level_2_id",geo_level_2_id);
                formDatas.append("geo_level_3_id",geo_level_3_id);
                formDatas.append("device_id",device_id);
                formDatas.append("name",name);
                formDatas.append("code",code);
                formDatas.append("pos_x",pos_x);
                formDatas.append("pos_y",pos_y);
                $.ajax({
                    type:"post",
                    contentType : false,
                    processData:false,
                    url: "${baseURL}/xkMonitor/update" ,
                    data:formDatas,
                    success:function () {
                        layer.alert('数据修改成功！',{
                            closeBtn: 0
                        });
                        monitorTable.ajax.reload();
                    }
                });
            },
            btn2:function (index,layero) {
            },
            success: function(){
                getMonitor(id);
                getEQ(deviceId);
                loadLoctionData(geoLevel1,geoLevel2,geoLevel3);
                getSensorType(sensorLevel1,sensorLevel2,sensorLevel3);
                $("#monitor_change_name_input").val(name);
                $("#monitor_change_alert_number_input").val(alarmNo);
                $("#monitor_change_pos_x_input").val(posX);
                $("#monitor_change_pos_y_input").val(posY);
                $('#monitor_change_map_div').empty();
                var imgs = "";
                imgs = '<img id="show_map" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="${baseURL}/xkGeoLocationMap/mapDownload?id='+geoLevel3+'" onclick="mapOnClick2(event)" />';
                $('#monitor_change_map_div').append(imgs);
                setTimeout("initBall()",1000);
                $("#monitor_change_floor_select2").change(function(){
                    var mapId = $('#monitor_change_floor_select2').val();
                    $('#monitor_change_map_div').empty();
                    var imgs = "";
                    imgs = '<img id="show_map2" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="${baseURL}/xkGeoLocationMap/mapDownload?id='+mapId+'" onclick="mapOnClick2(event)" />';
                    $('#monitor_change_map_div').append(imgs);
                    setTimeout("initBall()",1000);
                })
            }
        });
        function getMonitor(id){
            $.ajax({
                url:"${baseURL}/xkMonitor/get?id=" + id,
                async:false,
                success:function(data_in){
                    var jsonobj = data_in.data;
                    console.log(jsonobj);
                    name = jsonobj.name;
                    deviceId = jsonobj.device_id;
                    geoLevel1 = jsonobj.geo_level_1_id;
                    geoLevel2 = jsonobj.geo_level_2_id;
                    geoLevel3 = jsonobj.geo_level_3_id;
                    sensorLevel1 = jsonobj.sensor_level_1_id;
                    sensorLevel2 = jsonobj.sensor_level_2_id;
                    sensorLevel3 = jsonobj.sensor_level_3_id;
                    posX = jsonobj.pos_x;
                    posY =jsonobj.pos_y;
                    alarmNo = jsonobj.description;
                }
            })
        }
        function getEQ(deviceId) {
            $.ajax({
                url: "${baseURL}/xkDevice/getAll",
                async:false,
                success:function (data) {
                    eqData = data;
                    $('#monitor_change_router_div').cxSelect({
                        selects: ['monitor_change_router_select_class'],
                        jsonName: 'name',
                        jsonValue: 'id',
                        data:eqData.data
                    });
                    var cmb = document.getElementById("monitor_change_router_select");
                    option_items_select(cmb,deviceId);
                }
            });
        }
        function loadLoctionData(geoLevel1,geoLevel2,geoLevel3) {
            $.ajax({
                url: "${baseURL}/xkGeoLocation/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = data_in;
                    mapData = [];
                    var data = [];
                    for(var i  in jsonObj.data){
                        var level1 = jsonObj.data;
                        var level1Obj = {
                            text:level1[i].name,
                            id:level1[i].id,
                        };
                        if(level1[i].children != null)
                        {
                            var level2 = level1[i].children;
                            var level2Arr = [];
                            for(var j in level2){
                                var level2Obj = {
                                    text: level2[j].name,
                                    id: level2[j].id,
                                };
                                if(level2[j].children != null)
                                {
                                    var level3 = level2[j].children;
                                    var level3Arr = [];
                                    for(var k in level3){
                                        var level3Obj = {
                                            text: level3[k].name,
                                            id: level3[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                        var floorObj = {
                                            id: level3[k].id,
                                            picture: level3[k].picture
                                        };
                                        mapData.push(floorObj);
                                    }
                                    level2Obj .children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        data.push(level1Obj);
                    }
                    loctionData = data;
                }
            });
            $('#monitor_change_location_div').cxSelect({
                selects: ['monitor_change_area_select2_class', 'monitor_change_build_select2_class', 'monitor_change_floor_select2_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:false,
                jsonSub: 'children',
                data:loctionData
            });
            var cmb1 = document.getElementById("monitor_change_area_select2");
            option_items_select(cmb1,geoLevel1);
            var i,j;
            for(i=0; i<loctionData.length;i++){
                if(loctionData[i].id == geoLevel1){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_build_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_build_select2");
                    option_items_select(cmb2,geoLevel2);
                    break;
                }
            }
            for(j = 0;j<loctionData[i].children.length;j++){
                if(loctionData[i].children[j].id == geoLevel2){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_floor_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_floor_select2");
                    option_items_select(cmb3,geoLevel3);
                    break;
                }
            }
        }
        function getSensorType(sensorLevel1,sensorLevel2,sensorLevel3) {
            $.ajax({
                url:"${baseURL}/xkSensor/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = data_in;
                    sensorData = [];
                    for(var i in jsonObj.data){
                        var level1Data = jsonObj.data;
                        var level1Obj = {
                            id: level1Data[i].id,
                            text: level1Data[i].name,
                        };
                        if(level1Data[i].children != undefined){
                            var level2Data = level1Data[i].children;
                            var level2Arr = [];
                            for(var j in level2Data){
                                var level2Obj = {
                                    text: level2Data[j].name,
                                    id: level2Data[j].id,
                                };
                                if(level2Data[j].children != undefined)
                                {
                                    var level3Data = level2Data[j].children;
                                    var level3Arr = [];
                                    for(var k in level3Data){
                                        var level3Obj = {
                                            text: level3Data[k].name,
                                            id: level3Data[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                    }
                                    level2Obj.children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        sensorData.push(level1Obj);
                    }
                }
            });
            $('#monitor_sensor_change_div').cxSelect({
                selects: ['monitor_change_sensor1_select_class', 'monitor_change_sensor2_select_class','monitor_change_sensor3_select_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:false,
                jsonSub: 'children',
                data:sensorData
            });
            var cmb1 = document.getElementById("monitor_change_sensor1_select");
            option_items_select(cmb1,sensorLevel1);
            var i,j;
            for(i=0; i<sensorData.length;i++){
                if(sensorData[i].id == sensorLevel1){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor2_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_sensor2_select");
                    option_items_select(cmb2,sensorLevel2);
                    break;
                }
            }
            for(j = 0;j<sensorData[i].children.length;j++){
                if(sensorData[i].children[j].id == sensorLevel2){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor3_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_sensor3_select");
                    option_items_select(cmb3,sensorLevel3);
                    break;
                }
            }
        }
        function option_items_select(cmb,value){
            for(var i = 0;i<cmb.options.length;i++){
                if(cmb.options[i].value == value){
                    cmb.selectedIndex = i;
                    return;
                }
            }
        }
    }
    function initBall(){
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var x = $('#monitor_change_pos_x_input').val();
        var y = $('#monitor_change_pos_y_input').val();
        posSetBall2(x,y);
    }

    function mapOnClick2(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#monitor_change_pos_x_input').val(x.toFixed(10));
        $('#monitor_change_pos_y_input').val(y.toFixed(10));
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#monitor_change_map_div .mapBall").remove();
        }
        posSetBall2(x,y)
    }
    function posSetBall2(x,y) {
        var pos_x = (parseFloat(x) * 100);
        pos_x = pos_x>0?pos_x+'%':0;
        var pos_y = (parseFloat(y) * 100);
        pos_y = pos_y>0?pos_y+'%':0;
        $('<span class="mapBall ip_tooltip" style="top:calc('+pos_y+' - 10px);left: calc('+pos_x+' - 10px")>').css({
            width: 20,
            height: 20,
        }).appendTo($('#monitor_change_map_div '));
    }

    $('#delDataBtn').click(function () {
        var ID = $('#tree_click_id_del').val();
        if(ID != null){
            $.ajax({
                url: '${baseURL}/xkSensor/delete?id='+ ID,
                success:function (data) {
                    if(data.code == 0){
                        $('#tree_click_id_del').val("");
                        $('#tree_click_text_del').val("");
                        clear();
                        getTree();
                        layer.alert('删除成功！',{
                            closeBtn: 0
                        });
                    }
                    else{
                        layer.alert('操作失败：' + data,{
                            closeBtn: 0
                        });
                    }
                }
            });
        }
        else{
            layer.alert('请先点选树状图内的目标。',{
                closeBtn: 0
            });
        }
    });
    function isSpecial(str){
        var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）&mdash;—|{}【】‘；：”“'。，、？]");
        if(pattern.test(str)){
            return 1;
        }else {
            return 0;
        }
    }

</script>
</#if>

</body>
</html>